﻿using LibNiconico.NiconicoApi.Utils;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading.Tasks;

namespace LibNiconico.NiconicoApi.Login
{
    /// <summary>
    /// ニコニコログイン結果コード
    /// </summary>
    enum NicoLoginResultCode
    {

        
        /// <summary>
        /// ログイン成功
        /// </summary>
        Succeed,

        /// <summary>
        /// ログイン失敗
        /// </summary>
        Failed

    }


    /// <summary>
    /// ログインレスポンス
    /// </summary>
    public class NicoLoginResponse
    {
        private NicoLoginResponse(NicoLoginResultCode resultCode, NiconicoAuth auth)
        {
            ResultCode = resultCode;
            Auth = auth;
        }

        /// <summary>
        /// 成功か判定
        /// </summary>
        public bool Succeed
        {
            get
            {
                return ResultCode == NicoLoginResultCode.Succeed;
            }
        }

        internal NicoLoginResultCode ResultCode { get; private set; }

        internal NiconicoAuth Auth { get; private set; }

        internal static NicoLoginResponse Parse(CookieContainer cookieContainer)
        {
            

            
            if (NiconicoAuth.IsLoggedIn(cookieContainer))
            {
                var auth = new NiconicoAuth();
                auth.SetUserSession(cookieContainer);

                return new NicoLoginResponse(NicoLoginResultCode.Succeed, auth);

            }
            else
            {
                return new NicoLoginResponse(NicoLoginResultCode.Failed, null);
            }


        }
    }
}
